#!/usr/bin/env python3

def main():
    w = []
    m = []

    while True:
        s = input("入场登记(姓名 性别): ")
        if s == 'exit':
            break
        name, sex = s.split()
        if sex == 'A':
            m.append(name)
        else:
            w.append(name)

    num = len(m) if len(w) > len(m) else len(w)

    for i in range(3):
        print("第 %d 轮: " % (i + 1), end='')
        for j in range(num):
            name = m.pop(0)
            print("%s <==> " % name, end='')
            m.append(name)

            name = w.pop(0)
            print("%s " % name, end='')
            w.append(name)
        print()

if __name__ == "__main__":
    main()
